home *** CD-ROM | disk | FTP | other *** search
/ LG Super CD / LG Super CD.iso / bitpim / bitpim-0.62-setup.exe / {app} / bitpim.exe / os2emxpath.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-11-06  |  9.4 KB  |  369 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.3)
  3.  
  4. import os
  5. import stat
  6. __all__ = [
  7.     'normcase',
  8.     'isabs',
  9.     'join',
  10.     'splitdrive',
  11.     'split',
  12.     'splitext',
  13.     'basename',
  14.     'dirname',
  15.     'commonprefix',
  16.     'getsize',
  17.     'getmtime',
  18.     'getatime',
  19.     'getctime',
  20.     'islink',
  21.     'exists',
  22.     'isdir',
  23.     'isfile',
  24.     'ismount',
  25.     'walk',
  26.     'expanduser',
  27.     'expandvars',
  28.     'normpath',
  29.     'abspath',
  30.     'splitunc',
  31.     'curdir',
  32.     'pardir',
  33.     'sep',
  34.     'pathsep',
  35.     'defpath',
  36.     'altsep',
  37.     'extsep',
  38.     'realpath',
  39.     'supports_unicode_filenames']
  40. curdir = '.'
  41. pardir = '..'
  42. extsep = '.'
  43. sep = '/'
  44. altsep = '\\'
  45. pathsep = ';'
  46. defpath = '.;C:\\bin'
  47.  
  48. def normcase(s):
  49.     return s.replace('\\', '/').lower()
  50.  
  51.  
  52. def isabs(s):
  53.     s = splitdrive(s)[1]
  54.     if s != '':
  55.         pass
  56.     return s[:1] in '/\\'
  57.  
  58.  
  59. def join(a, *p):
  60.     path = a
  61.     for b in p:
  62.         if isabs(b):
  63.             path = b
  64.             continue
  65.         if path == '' or path[-1:] in '/\\:':
  66.             path = path + b
  67.             continue
  68.         path = path + '/' + b
  69.     
  70.     return path
  71.  
  72.  
  73. def splitdrive(p):
  74.     if p[1:2] == ':':
  75.         return (p[0:2], p[2:])
  76.     
  77.     return ('', p)
  78.  
  79.  
  80. def splitunc(p):
  81.     if p[1:2] == ':':
  82.         return ('', p)
  83.     
  84.     firstTwo = p[0:2]
  85.     if firstTwo == '/' * 2 or firstTwo == '\\' * 2:
  86.         normp = normcase(p)
  87.         index = normp.find('/', 2)
  88.         if index == -1:
  89.             return ('', p)
  90.         
  91.         index = normp.find('/', index + 1)
  92.         if index == -1:
  93.             index = len(p)
  94.         
  95.         return (p[:index], p[index:])
  96.     
  97.     return ('', p)
  98.  
  99.  
  100. def split(p):
  101.     (d, p) = splitdrive(p)
  102.     i = len(p)
  103.     while i and p[i - 1] not in '/\\':
  104.         i = i - 1
  105.     (head, tail) = (p[:i], p[i:])
  106.     head2 = head
  107.     while head2 and head2[-1] in '/\\':
  108.         head2 = head2[:-1]
  109.     if not head2:
  110.         pass
  111.     head = head
  112.     return (d + head, tail)
  113.  
  114.  
  115. def splitext(p):
  116.     (root, ext) = ('', '')
  117.     for c in p:
  118.         if c in [
  119.             '/',
  120.             '\\']:
  121.             (root, ext) = (root + ext + c, '')
  122.             continue
  123.         if c == '.':
  124.             if ext:
  125.                 (root, ext) = (root + ext, c)
  126.             else:
  127.                 ext = c
  128.         ext
  129.         if ext:
  130.             ext = ext + c
  131.             continue
  132.         root = root + c
  133.     
  134.     return (root, ext)
  135.  
  136.  
  137. def basename(p):
  138.     return split(p)[1]
  139.  
  140.  
  141. def dirname(p):
  142.     return split(p)[0]
  143.  
  144.  
  145. def commonprefix(m):
  146.     if not m:
  147.         return ''
  148.     
  149.     prefix = m[0]
  150.     for item in m:
  151.         for i in range(len(prefix)):
  152.             if prefix[:i + 1] != item[:i + 1]:
  153.                 prefix = prefix[:i]
  154.                 if i == 0:
  155.                     return ''
  156.                 
  157.                 break
  158.                 continue
  159.         
  160.     
  161.     return prefix
  162.  
  163.  
  164. def getsize(filename):
  165.     return os.stat(filename).st_size
  166.  
  167.  
  168. def getmtime(filename):
  169.     return os.stat(filename).st_mtime
  170.  
  171.  
  172. def getatime(filename):
  173.     return os.stat(filename).st_atime
  174.  
  175.  
  176. def getctime(filename):
  177.     return os.stat(filename).st_ctime
  178.  
  179.  
  180. def islink(path):
  181.     return False
  182.  
  183.  
  184. def exists(path):
  185.     
  186.     try:
  187.         st = os.stat(path)
  188.     except os.error:
  189.         return False
  190.  
  191.     return True
  192.  
  193.  
  194. def isdir(path):
  195.     
  196.     try:
  197.         st = os.stat(path)
  198.     except os.error:
  199.         return False
  200.  
  201.     return stat.S_ISDIR(st.st_mode)
  202.  
  203.  
  204. def isfile(path):
  205.     
  206.     try:
  207.         st = os.stat(path)
  208.     except os.error:
  209.         return False
  210.  
  211.     return stat.S_ISREG(st.st_mode)
  212.  
  213.  
  214. def ismount(path):
  215.     (unc, rest) = splitunc(path)
  216.     if unc:
  217.         return rest in ('', '/', '\\')
  218.     
  219.     p = splitdrive(path)[1]
  220.     if len(p) == 1:
  221.         pass
  222.     return p[0] in '/\\'
  223.  
  224.  
  225. def walk(top, func, arg):
  226.     
  227.     try:
  228.         names = os.listdir(top)
  229.     except os.error:
  230.         return None
  231.  
  232.     func(arg, top, names)
  233.     exceptions = ('.', '..')
  234.     for name in names:
  235.         if name not in exceptions:
  236.             name = join(top, name)
  237.             if isdir(name):
  238.                 walk(name, func, arg)
  239.             
  240.         isdir(name)
  241.     
  242.  
  243.  
  244. def expanduser(path):
  245.     if path[:1] != '~':
  246.         return path
  247.     
  248.     (i, n) = (1, len(path))
  249.     while i < n and path[i] not in '/\\':
  250.         i = i + 1
  251.     if i == 1:
  252.         if 'HOME' in os.environ:
  253.             userhome = os.environ['HOME']
  254.         elif not ('HOMEPATH' in os.environ):
  255.             return path
  256.         else:
  257.             
  258.             try:
  259.                 drive = os.environ['HOMEDRIVE']
  260.             except KeyError:
  261.                 drive = ''
  262.  
  263.             userhome = join(drive, os.environ['HOMEPATH'])
  264.     else:
  265.         return path
  266.     return userhome + path[i:]
  267.  
  268.  
  269. def expandvars(path):
  270.     if '$' not in path:
  271.         return path
  272.     
  273.     import string
  274.     varchars = string.letters + string.digits + '_-'
  275.     res = ''
  276.     index = 0
  277.     pathlen = len(path)
  278.     while index < pathlen:
  279.         c = path[index]
  280.         if c == "'":
  281.             path = path[index + 1:]
  282.             pathlen = len(path)
  283.             
  284.             try:
  285.                 index = path.index("'")
  286.                 res = res + "'" + path[:index + 1]
  287.             except ValueError:
  288.                 res = res + path
  289.                 index = pathlen - 1
  290.             except:
  291.                 None<EXCEPTION MATCH>ValueError
  292.             
  293.  
  294.         None<EXCEPTION MATCH>ValueError
  295.         if c == '$':
  296.             if path[index + 1:index + 2] == '$':
  297.                 res = res + c
  298.                 index = index + 1
  299.             elif path[index + 1:index + 2] == '{':
  300.                 path = path[index + 2:]
  301.                 pathlen = len(path)
  302.                 
  303.                 try:
  304.                     index = path.index('}')
  305.                     var = path[:index]
  306.                     if var in os.environ:
  307.                         res = res + os.environ[var]
  308.                 except ValueError:
  309.                     res = res + path
  310.                     index = pathlen - 1
  311.                 except:
  312.                     None<EXCEPTION MATCH>ValueError
  313.                 
  314.  
  315.             None<EXCEPTION MATCH>ValueError
  316.             var = ''
  317.             index = index + 1
  318.             c = path[index:index + 1]
  319.             while c != '' and c in varchars:
  320.                 var = var + c
  321.                 index = index + 1
  322.                 c = path[index:index + 1]
  323.             if var in os.environ:
  324.                 res = res + os.environ[var]
  325.             
  326.             if c != '':
  327.                 res = res + c
  328.             
  329.         else:
  330.             res = res + c
  331.         index = index + 1
  332.     return res
  333.  
  334.  
  335. def normpath(path):
  336.     path = path.replace('\\', '/')
  337.     (prefix, path) = splitdrive(path)
  338.     while path[:1] == '/':
  339.         prefix = prefix + '/'
  340.         path = path[1:]
  341.     comps = path.split('/')
  342.     i = 0
  343.     while i < len(comps):
  344.         if comps[i] == '.':
  345.             del comps[i]
  346.             continue
  347.         if comps[i] == '..' and i > 0 and comps[i - 1] not in ('', '..'):
  348.             del comps[i - 1:i + 1]
  349.             i = i - 1
  350.             continue
  351.         if comps[i] == '' and i > 0 and comps[i - 1] != '':
  352.             del comps[i]
  353.             continue
  354.         i = i + 1
  355.     if not prefix and not comps:
  356.         comps.append('.')
  357.     
  358.     return prefix + '/'.join(comps)
  359.  
  360.  
  361. def abspath(path):
  362.     if not isabs(path):
  363.         path = join(os.getcwd(), path)
  364.     
  365.     return normpath(path)
  366.  
  367. realpath = abspath
  368. supports_unicode_filenames = False
  369.